/**  
 * @Title: MyLongTypeHandler.java  
 * @Package com.blog4java.mybatis.example.typeHandler  
 * @Description: TODO(用一句话描述该文件做什么)  
 * @author suyuhao  
 * @date 2025-06-05 02:10:22   
 */
package com.blog4java.mybatis.example.typeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

/**  
* @ClassName: MyLongTypeHandler  
* @Description: 自定义long类型转换器
* @author suyuhao  
* @date 2025-06-05 02:10:22
*/
public class MyLongTypeHandler extends BaseTypeHandler<Long>{

	/* (non-Javadoc)
	 * @see org.apache.ibatis.type.BaseTypeHandler#setNonNullParameter(java.sql.PreparedStatement, int, java.lang.Object, org.apache.ibatis.type.JdbcType)
	 */
	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, Long parameter, JdbcType jdbcType)
			throws SQLException {
		// TODO Auto-generated method stub
		ps.setLong(i, parameter);
	}

	/* (non-Javadoc)
	 * @see org.apache.ibatis.type.BaseTypeHandler#getNullableResult(java.sql.ResultSet, java.lang.String)
	 */
	@Override
	public Long getNullableResult(ResultSet rs, String columnName) throws SQLException {
		// TODO Auto-generated method stub
	    long result = rs.getLong(columnName);
	    return result == 0 && rs.wasNull() ? null : result;
	}

	/* (non-Javadoc)
	 * @see org.apache.ibatis.type.BaseTypeHandler#getNullableResult(java.sql.ResultSet, int)
	 */
	@Override
	public Long getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		// TODO Auto-generated method stub
	    long result = rs.getLong(columnIndex);
	    return result == 0 && rs.wasNull() ? null : result;
	}

	/* (non-Javadoc)
	 * @see org.apache.ibatis.type.BaseTypeHandler#getNullableResult(java.sql.CallableStatement, int)
	 */
	@Override
	public Long getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		// TODO Auto-generated method stub
	    long result = cs.getLong(columnIndex);
	    return result == 0 && cs.wasNull() ? null : result;
	}

}
